package com.huidu.bitrade.server;

import com.mongodb.MongoClient;
import com.mongodb.ServerAddress;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class MongodbClient {

    @Value("${server.monitor.mongodb.url:}")
    private String url;
    @Value("${server.monitor.mongodb.port:}")
    private Integer port;
    public boolean client(){
        MongoClient mongo = new MongoClient(new ServerAddress(url, port));
        try {
            mongo.getAddress();
        } catch (Exception e) {
            System.out.println("Database unavailable!");
            mongo.close();
            return Boolean.FALSE;
        }
        mongo.close();
        return Boolean.TRUE;
    }
}
